package com.nd.android.musicboxlibrary.util.fastDateUtil;

/**
 * <p>
 * Helper class for creating compound objects.
 * </p>
 * <p>
 * One use for this class is to create a hashtable key out of multiple objects.
 * </p>
 */
public class Pair {
    private final Object mObj1;

    private final Object mObj2;

    /**
     * Constructs an instance of <code>Pair</code> to hold the specified objects.
     * 
     * @param obj1
     *            one object in the pair
     * @param obj2
     *            second object in the pair
     */
    public Pair(Object obj1, Object obj2) {
        mObj1 = obj1;
        mObj2 = obj2;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof Pair)) {
            return false;
        }

        Pair key = (Pair) obj;

        return (mObj1 == null ? key.mObj1 == null : mObj1.equals(key.mObj1))
                && (mObj2 == null ? key.mObj2 == null : mObj2.equals(key.mObj2));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return (mObj1 == null ? 0 : mObj1.hashCode()) + (mObj2 == null ? 0 : mObj2.hashCode());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "[" + mObj1 + ':' + mObj2 + ']';
    }
}
